<?php
namespace frontend\controllers;

use Yii;
use yii\web\Controller;

/**
 * action controller
 */
class ActionController extends Controller
{
    public $enableCsrfValidation = false;

    /**
     * Displays homepage.
     *
     * @return mixed
     */
    public function actionIndex()
    {
        try {

            $rawBody = Yii::$app->request->getRawBody();

            $arrayData = json_decode($rawBody, true);
            if (empty($arrayData)){
                $data = $_POST;
                $arrayData = json_decode(json_encode( $data), true);
            }
            if (is_array($arrayData) && isset($arrayData['action'])) {
                //Yii::info($arrayData['action'] . " req start");
                $handler = new \frontend\api\ApiHandler();
                $returnData = $handler->handleAction($arrayData);
                //Yii::info($arrayData['action'] . " req end");
                header('Content-type: application/json; charset=UTF-8');
                echo json_encode($returnData, JSON_UNESCAPED_UNICODE);
            }
        } catch(\Exception $e) {
        }

        Yii::$app->end();
    }

}
